/*
 * $Id: GarbageFreeBooleanFormatter.java 66 2013-01-06 10:16:51Z vladimirow@mail.ru $
 * $HeadURL: http://ultralog.googlecode.com/svn/ultralog/trunk/src/java/com/google/code/ultralog/formatter/gfree/GarbageFreeBooleanFormatter.java $
 *
 * This file is a part of ultralog project (http://code.google.com/p/ultralog/).
 * Released under New BSD License.
 */
package com.google.code.ultralog.formatter.gfree;

import com.google.code.ultralog.formatter.BooleanFormatter;
import com.google.code.ultralog.utils.CharacterOutputStream;

/**
 * Garbage free implementation of {@link BooleanFormatter} interface.
 *
 * @author Mikhail Vladimirov
 */
public class GarbageFreeBooleanFormatter implements BooleanFormatter
{
    /**
     * Singleton instance of the formatter.
     */
    public final static GarbageFreeBooleanFormatter INSTANCE =
        new GarbageFreeBooleanFormatter ();

    private GarbageFreeBooleanFormatter ()
    {
        // Do nothing
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void format (boolean value, CharacterOutputStream output)
    {
        if (output == null)
            throw new IllegalArgumentException ("Output is null");

        if (value)
            output.write ("true", 0, 4);
        else
            output.write ("false", 0, 5);
    }
}
